package com.hmdp.utils;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 张一恒
 * @version 1.0
 * @description: TODO
 * @date 2022/11/17 23:09
 */
public class LoginInterceptor implements HandlerInterceptor {

    //前置拦截器
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //判断当前用户是否存在
        if(UserHolder.getUser() == null){
            response.setStatus(401);
            return false;
        }
        //如果存在 放行
        return true;
    }
}
